import requests
import hashlib
import json

headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
         'Content - Type':'application / json;charset = UTF - 8'
}
url_base=r'http://192.168.142.202:3000/'
url_login=url_base+r'/jshERP-boot/user/login'

# 登录
username='zh01'
password='123456'
md5=hashlib.md5(password.encode())
password_md5=md5.hexdigest()
data_login={'loginName':username,'password':password_md5}
resp=requests.post(url_login,json=data_login,headers=headers,verify=False)
token=resp.json()['data']['token']
print(token)

# 角色新增
# name='ceshi02'
# type='全部数据'
# headers['X-Access-Token']=token
# url_role_add=url_base+r'/jshERP-boot/role/add'
# data_role_add={'name':name,'type':type}
# resp=requests.post(url_role_add,json=data_role_add,headers=headers,verify=False)
# print(resp.text)


# 角色修改
# id=43
# name='ceshi02'
# type='全部数据'
# headers['X-Access-Token']=token
# url_base_mod=url_base+r'/jshERP-boot/role/update'
# data_role_mod={"deleteFlag":"0","enabled":True,"id":id,"name":name,"tenantId":148,"type":type}
# resp=requests.put(url_base_mod,json=data_role_mod,headers=headers,verify=False)
# print(resp.text)

name='测试角色'
description = ''
headers['X-Access-Token']=token
url_role_query=url_base+r'/jshERP-boot/role/list'
search_dict={'name':name}
search_str=json.dumps(search_dict)
data_role_query={'search':search_str,'column':'createTime','order':'desc',
                 'field':'id,,,action,name,type,priceLimitStr,description,sort,enabled',
                 'currentPage':'1','pageSize':'10'}
resp=requests.get(url_role_query,params=data_role_query,headers=headers,verify=False)
print(resp.text)
